package com.ltmonitor.service.impl;

import java.io.Serializable;
import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.ltmonitor.dao.IBaseHibernateDao;
import com.ltmonitor.dao.impl.QueryResult;
import com.ltmonitor.service.IBaseService;

@Transactional(propagation = Propagation.REQUIRED) 
public abstract class BaseService <K extends Serializable,T extends Serializable> implements IBaseService<K,T> {
	@Autowired
	protected IBaseHibernateDao<K,T> baseDao;		//从容器中注入session工厂【无需get,set方法】
	
	@Override
	public K save(T t) {
		return baseDao.save(t);
	}

	@Override
	public void saveOrUpdateAll(Collection<T> ct) {
		baseDao.saveOrUpdateAll(ct);
	}

	@Override
	public T load(K id) {
		return baseDao.findById(id);
	}

	@Override
	public T update(T t) {
		return baseDao.update(t);
	}

	@Override
	public T saveOrUpdate(T t) {
		return baseDao.saveOrUpdate(t);
	}

	@Override
	public void delete(T t) {
		baseDao.delete(t);
	}

	@Override
	public void deleteAll(Collection<T> ct) {
		baseDao.deleteAll(ct);
	}

	@Override
	public boolean deleteById(K id) {
		return baseDao.deleteById(id);
	}

	@Override
	public Collection<T> loadAll() {
		return baseDao.loadAll();
	}

	@Override
	public QueryResult<T> load(int page, int rows) {
		return baseDao.load(page, rows);
	}

	@Override
	public long getTotalCount() {
		return baseDao.getTotalCount();
	}
	/******************************HQL******************************/

	@Override
	public QueryResult<T> getScrollData() {
		return baseDao.getScrollData();
	}

	@Override
	public QueryResult<T> getScrollData(int firstResult, int maxResult) {
		return baseDao.getScrollData(firstResult, maxResult);
	}

	@Override
	public QueryResult<T> getScrollData(int firstResult, int maxResult,
			LinkedHashMap<String, String> orderby) {
		return baseDao.getScrollData(firstResult, maxResult, orderby);
	}

	@Override
	public QueryResult<T> getScrollData(int firstResult, int maxResult,
			String where, Object[] params) {
		return baseDao.getScrollData(firstResult, maxResult, where, params);
	}

	@Override
	public QueryResult<T> getScrollData(int firstResult, int maxResult,
			String where, Object[] params, LinkedHashMap<String, String> orderby) {
		return baseDao.getScrollData(firstResult, maxResult, where, params, orderby);
	}

	@Override
	public boolean deleteFakeById(K id) {
		
		return baseDao.deleteFakeById(id);
	}

	@Override
	public void deleteFake(T t) {
		
		 baseDao.deleteFake(t);
	}

	@Override
	public List<T> query(String hql, Object value) {
		
		return baseDao.query(hql, value);
	}

	@Override
	public List<T> query(String hql, Object[] values) {
		
		return baseDao.query(hql, values);
	}

	@Override
	public List<T> queryByNamedParam(String hql, String paramName, Object value) {
		
		return baseDao.queryByNamedParam(hql, paramName, value);
	}

	@Override
	public List<T> query(String hql) {
		
		return baseDao.query(hql);
	}

	@Override
	public T find(String hsql, Object[] values) {
		
		return baseDao.find(hsql, values);
	}

	@Override
	public T find(String hsql, Object value) {
		
		return baseDao.find(hsql, value);
	}

	@Override
	public T find(String hsql) {
		
		return baseDao.find(hsql);
	}

	

	/**
	 * 根据HQL语句和传参，批量更新数据库，注意hql是update .. set ..开始的语句，不是查询语句
	 * @param hql hql是update .. set ..开始的语句，不是查询语句
	 * @param values 要更新的参数值
	 */

	@Override
	public void bulkUpdate(String hql, Object[] values)
	{
		baseDao.bulkUpdate(hql, values);
	}


}
